<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <input type="text" id="ip1" />
    <input type="text" id="ip2" />
    <input type="text" id="ip3" />
    <br />
    <button id="btn">行刑</button>

    <script>
      function eatNoodle() {
        console.log("买面");
        console.log("下面");
        console.log("吃面");
        console.log("去一趟香格里拉");
      }
      //   eatNoodle()
    </script>

    <script>
      // - 判断一个整数，属于哪个范围：大于0；小于0；等于0
      function fn1() {
        // 将用户输入的数值字符串隐式地转换为number
        var value = ip1.value * 1;

        // if(value > 0){
        //     alert("大于0")
        // }else if(value < 0){
        //     alert("小于0")
        // }else{
        //     alert("等于0")
        // }

        switch (true) {
          case value > 0:
            alert("大于0");
            break;
          case value < 0:
            alert("小于0");
            break;
          case value === 0:
            alert("等于0");
            break;

          // 处理NaN
          default:
            console.log(
              "代码执行到此处可免费到前台领取30Koffer一个+女朋友一个"
            );
            break;
        }
      }

      // - 判断一个整数是偶数还是奇数，并输出判断结果
      function fn2() {
        var num = ip1.value * 1;
        if (num % 2 === 0) {
          alert("num偶数");
        } else {
          alert("num奇数");
        }

        // if ((ip1.value * 1) % 2 === 0) {
        //   alert("偶数");
        // } else {
        //   alert("奇数");
        // }
      }

      // - 开发一款软件，根据公式（身高-108）*2=标准体重，可以有10斤左右的浮动。来观察测试者体重是否合适
      function fn3() {
        var height = ip1.value * 1;
        var weight = ip2.value * 1;

        //   套公式计算标准体重
        var stdWeight = (height - 108) * 2;

        if (weight >= stdWeight - 10 && weight <= stdWeight + 10) {
          alert("阁下真魔鬼身材也");
        } else {
          alert("spicy chicken");
        }
      }

      // - 输入月份，显示当月的天数(31/30/28)
      // 要求：利用case穿透简化代码
      function fn4() {
        var month = ip1.value * 1;
        var days = 0;

        switch (month) {
          case 1:
          case 3:
          case 5:
          case 7:
          case 8:
          case 10:
          case 12:
            days = 31;
            break;
          case 4:
          case 6:
          case 9:
          case 11:
            days = 30;
            break;
          case 2:
            days = 28;
            break;
          default:
            days = "你妈喊你回家玩泥巴";
            break;
        }

        alert("您输入的月份天数是:" + days);
      }

      // - 根据输入的【天数：一年当中的第123天】判断落在几月（假设都是平年）
      function fn5() {
        var days = ip1.value * 1;
        var month = 0;

        switch (true) {
          case days > 0 && days <= 31:
            month = 1;
            break;
          case days > 31 && days <= 31 + 28:
            month = 2;
            break;
          case days > 31 + 28 && days <= 31 + 28 + 31:
            month = 3;
            break;

          default:
            month = "4月或以后";
            break;
        }

        alert("您输入的天数落点月份是" + month);
      }

      function fn5x() {
        var days = ip1.value * 1;
        var month = 0;

        var start = 0;

        switch (true) {
          case (days > 0 && days <= 31) || !(start += 31):
            month = 1;
            break;
          case (days > start && days <= start + 28) || !(start += 28):
            month = 2;
            break;
          case (days > start && days <= start + 31) || !(start += 31):
            month = 3;
            break;
          case (days > start && days <= start + 30) || !(start += 30):
            month = 4;
            break;
          case (days > start && days <= start + 31) || !(start += 31):
            month = 5;
            break;
          case (days > start && days <= start + 30) || !(start += 30):
            month = 6;
            break;
          case (days > start && days <= start + 31) || !(start += 31):
            month = 7;
            break;
          case (days > start && days <= start + 31) || !(start += 31):
            month = 8;
            break;
          case (days > start && days <= start + 30) || !(start += 30):
            month = 9;
            break;
          case (days > start && days <= start + 31) || !(start += 31):
            month = 10;
            break;
          case (days > start && days <= start + 30) || !(start += 30):
            month = 11;
            break;
          case (days > start && days <= start + 31) || !(start += 31):
            month = 12;
            break;

          default:
            month = "——【你妈喊你回家玩泥巴】";
            break;
        }

        alert("您输入的天数落点月份是" + month);
      }

      // - 根据输入的年月日，判断是这一年的第几天
      // 提示：要考虑闰年(闰年：整四不整百 或者 整四百)
      function fn6() {
        var year = ip1.value * 1;
        var month = ip2.value * 1;
        var date = ip3.value * 1;

        var premonthDays = 0
        /* 将前置月份的总天数穿糖葫芦 */
        switch(month){
            case 12:
                premonthDays += 30;//穿上11月的天数
            case 11:
                premonthDays += 31;//穿上10月的天数
            case 10:
                premonthDays += 30;
            case 9:
                premonthDays += 31;
            case 8:
                premonthDays += 31;
            case 7:
                premonthDays += 30;
            case 6:
                premonthDays += 31;
            case 5:
                premonthDays += 30;
            case 4:
                premonthDays += 31;
            case 3:
                premonthDays += 28;
            case 2:
                premonthDays += 31;
            case 1:
                premonthDays += 0;
                break
            default:
                break
        }


        //   总天数 = 前置月的总天数 + 当月的日期
        var days = premonthDays + date;
        alert(days)
      }

      btn.onclick = function () {
        fn6();//调用我没的函数
      };
    </script>
  </body>
</html>
